/**
 * Project of Vehicle Routing Problem with Time Windows implements 
 * some of well-known algorithms for solving VRPTW and presents new 
 * one.
 *
 * @author Michal Drobny  
 */

package logic.route;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import logic.destination.Destination;

/**
 * Represents a simple route. Simple route is described as a list of
 * destinations in order we go through them.
 * 
 * @author Michal Drobny
 * @date 2.10.2014
 */
public class SimpleRoute implements Route {

	private List<Destination> destinations;

	/**
	 * Constructor.
	 */
	public SimpleRoute() {
		super();
		this.destinations = new LinkedList<Destination>();
	}

	/**
	 * Constructor.
	 * 
	 * @param destinations
	 *            The destinations
	 */
	public SimpleRoute(List<Destination> destinations) {
		super();
		if (destinations != null)
			this.destinations = destinations;
	}

	/**
	 * Adds the given destination to the list of destinations.
	 * 
	 * @param destination
	 *            The destination
	 */
	public void addDestination(Destination destination) {
		destinations.add(destination);
	}

	@Override
	public List<Destination> getDestinations() {
		return destinations;
	}

	@Override
	public Destination[] getOrderedDestinations(Destination from) {
		
		if (!destinations.contains(from))
			return null;
		
		int index = 0;
		for (Destination dest : destinations)
			if (dest.equals(from))
				break;
			else
				++index;
		
		Collections.rotate(destinations, -index);
		return destinations.toArray(new Destination[destinations.size()]);
	}
}